package cn.itsource;

import cn.itsource.config.RabbutMQConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = App.class)
@RunWith(SpringRunner.class)
//发送者
public class Sender {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Test
    public void testSendByTopics() throws InterruptedException {
        for (int i = 0; i < 5; i++) {

            String message = "sms email inform to user" + i;

            rabbitTemplate.convertAndSend(
                    //交换机的名字
                    RabbutMQConfig.EXCHANGE_TOPICS_INFORM,
                    "email.xx",
                    message);

            System.out.println("消息发送完毕....");
        }

        Thread.sleep(10000);
    }
}

